package com.ccjq.shosestore.shoppingcart.service.impl;

import com.ccjq.shosestore.core.utils.ArithUtils;
import com.ccjq.shosestore.core.utils.UuidUtils;
import com.ccjq.shosestore.shoppingcart.dao.CarDao;
import com.ccjq.shosestore.shoppingcart.dao.impl.CarDaoImpl;
import com.ccjq.shosestore.shoppingcart.po.CarPo;
import com.ccjq.shosestore.shoppingcart.po.ProductCarPo;
import com.ccjq.shosestore.shoppingcart.service.CarService;

import java.util.ArrayList;
import java.util.List;

public class CarServiceImpl implements CarService {
    CarDao carDao = new CarDaoImpl();
    public int insertAll(CarPo carPo) {
        String setShopping_cart_id = UuidUtils.generateShortUUID("c", 10);
        carPo.setShopping_cart_id(setShopping_cart_id);
        int result = carDao.insertAll(carPo);
        return result;
    }
    public int deleteCar(String shopping_cart_id) {
        int result = carDao.deleteCar(shopping_cart_id);
        return result;
    }
    public int updateCar(int quantity, String shopping_cart_id) {
        int result = carDao.updateCar(quantity,shopping_cart_id);
        return result;
    }
    public List<ProductCarPo> selectCar(String user_id) {
        List<ProductCarPo> List = new ArrayList<ProductCarPo>();
        List<ProductCarPo> CarList = carDao.selectCar(user_id);
        for(ProductCarPo pp:CarList){
            ProductCarPo carPo = new ProductCarPo();
            carPo.setProduct_id(pp.getProduct_id());
            carPo.setDescription(pp.getDescription());
            carPo.setPrice(pp.getPrice());
            carPo.setModel(pp.getModel());
            carPo.setFeature(pp.getFeature());
            carPo.setImgpath(pp.getImgpath());
            carPo.setMovalty_status(pp.getMovalty_status());
            carPo.setPublish_date(pp.getPublish_date());
            carPo.setCategory_id(pp.getCategory_id());
            carPo.setShopping_cart_id(pp.getShopping_cart_id());
            carPo.setQuantity(pp.getQuantity());
            carPo.setUser_id(pp.getUser_id());
            carPo.setSale(ArithUtils.mul(pp.getQuantity(), pp.getPrice()));
            List.add(carPo);
        }
        return List;
    }
    public int selectStock(String product_id) {
        int result = carDao.selectStock(product_id);
        return result;
    }
}
